//
//  BaseCollectionViewController.swift
//  GhostWorld
//
//  Created by Kam on 2018/4/6.
//  Copyright © 2018 LKGood. All rights reserved.
//

import UIKit

private let reuseIdentifier = "Cell"

class BaseCollectionViewController: UICollectionViewController {
  
  // MARK: - IBOutlets
  
  
  
  // MARK: - Private vars
  
  
  
  // MARK: - Private methods
  
  private func drawBackgroundColor() {
    //    let bgView = UIView(frame: view.bounds)
    let gradient = CAGradientLayer()
    gradient.frame = view.bounds
    gradient.colors = [
      UIColor(fromRGB: 0x404040).cgColor,
      UIColor(fromRGB: 0x131313).cgColor
    ]
    gradient.locations = [0.2, 1.0]
    
    view.layer.insertSublayer(gradient, at: 0)
  }
  
  // MARK: - Public vars
  
  var prefersLargeTitles = false
  var shouldRenderGradientBackground = true
  
  // MARK: - Lifecycle
  
  override func viewDidLoad() {
    super.viewDidLoad()
    
    if #available(iOS 11.0, *) {
      extendedLayoutIncludesOpaqueBars = true
    }
  }
  
  override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    
    if #available(iOS 11.0, *) {
      navigationController?.navigationBar.prefersLargeTitles = prefersLargeTitles
    }
  }
  
  override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
    
    if shouldRenderGradientBackground {
      drawBackgroundColor()
    }
  }
  
  override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
  }
  
  // MARK: - IBActions
  
  
  
  // MARK: - Public methods
  
}

// MARK: - UICollectionViewDataSource

extension BaseCollectionViewController {
  
  override func numberOfSections(in collectionView: UICollectionView) -> Int {
    // #warning Incomplete implementation, return the number of sections
    return 0
  }
  
  override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    // #warning Incomplete implementation, return the number of items
    return 0
  }
  
  override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath)
    
    // Configure the cell
    
    return cell
  }
}
